<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/7/22
 * Time: 16:26
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Franchisee extends Base {
    /**
     * 首页展示
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $yy_phone = trim(input('yy_phone'), ' ');
            $yy_status = input('yy_status');
            $where = [];

            if(isset($yy_phone) && $yy_phone != ''){
                $where['franchisee_phone'] = ['like', '%' . $yy_phone . '%'];
            }
            if(isset($yy_status) && $yy_status != ''){
                $where['franchisee_status'] = $yy_status;
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('franchisee')->where($where)->count();// 获取总条数
            $lists = Db::name('franchisee')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('franchisee_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    /**
     * 标记已处理
     * @return \think\response\Json
     */
    public function handle(){
        $yy_id = input('id');
        $res = Db::table('up_franchisee')
            ->where('franchisee_id', $yy_id)
            ->update(['franchisee_status' => 2]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    /**
     * 拒绝
     * @return \think\response\Json
     */
    public function refuse(){
        if(Request::instance()->isPost()){
            $handle_content = input('param.handle_content');
            $id = input('param.id');
            $data['franchisee_yy'] = $handle_content;
            $data['franchisee_status'] = 3;
            $res = Db::table('up_franchisee')->where('franchisee_id',$id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '操作成功']);
            }else{
                return json(['code' => 100, 'msg' => '操作失败']);
            }
        }
        $id = input('param.franchisee_id');
        $this->assign('id',$id);
       return $this->fetch();
    }
}